import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import postCssPxToRem from "postcss-pxtorem";
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
  css: {
    postcss: {
      plugins: [
        postCssPxToRem({
          rootValue: 37.5, // 1rem的大小
          propList: ["*"], // 需要转换的属性，这里选择全部都进行转换
        }),
      ],
    },
  },
  server: {
    proxy: {
      "/app-dev": {
        target: "http://gmall-h5-api.atguigu.cn/",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/app-dev/, ""),
      },
      "/api": {
        // 只对请求路由以/foo开头的请求进行代理转发
        target: "https://m.you.163.com", // 转发的目标url
        changeOrigin: true, // 支持跨域
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
});
